<%--
  Created by IntelliJ IDEA.
  User: ZRETC
  Date: 2024/8/28
  Time: 8:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="${pageContext.request.contextPath}/js/jquery-1.11.1.js"></script>
    <script>
        $(function(){//加载页面时执行
            $("#testException").click(function(){
                //alert("111111111111111111111")
                $.ajax({
                    contentType: "application/json",
                    type: "POST",
                    url: "save",
                    data: '{"name":"jock","age":"11"}',
                    dataType: "text",
                    success:function(data){
                        console.log(data);
                    },
                    error:function(){
                        alert("出错了！")
                    }
                })

            })

            $("#testAjaxReturnJson").click(function(){
                $.ajax({
                    type: "post",
                    url: "ajaxReturnJson",
                    success:function (data){
                        console.log(data)
                        console.log(data['name'] + "," + data['age'])
                    }
                })
            })

            $("#testAjaxReturnJsonList").click(function(){
                $.ajax({
                    type: "post",
                    url: "ajaxReturnJsonList",
                    success:function (data){
                        console.log(data)
                        console.log(data.length)

                        console.log(data[0]['name']);
                        console.log(data[1]['name']);
                    }
                })
            })
        })
    </script>
</head>
<body>
<a href="#" id="testException">访问springmvc后台controller，传递Json格式pojo</a>
<a href="#" id="testAjaxReturnJson">testAjaxReturnJson</a>
<a href="#" id="testAjaxReturnJsonList">testAjaxReturnJsonList</a>
</body>
</html>